package com.woniu.dating.controller;

import com.woniu.common.annotation.LoginDating;
import com.woniu.common.entity.Result;
import com.woniu.common.entity.ResultCode;
import com.woniu.common.utils.StringUtils;
import com.woniu.dating.dto.GameTestDTO;
import com.woniu.dating.pojo.DatingGame;
import com.woniu.dating.service.IDatingGameService;
import com.woniu.dating.vo.DatingLoginVO;
import com.woniu.dating.vo.MatchingDatingVO;
import com.woniu.dating.vo.RecommendVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 玖柒
 * @since 2023-05-20
 */
@RestController
@RequestMapping("/datingGame")
@Api(tags = "游戏测试")
public class DatingGameController {

    @Resource
    private IDatingGameService datingGameService;

    /**
     * 接受用户传回的游戏答案，并保存到数据库中
     */
    @ApiOperation("游戏结果")
    @PostMapping("/game")
    public Result addDatingGame(@RequestBody GameTestDTO gameTestDTO, @LoginDating DatingLoginVO datingLoginVO) {
        //1.判断用户有没有游戏记录，有则生成。无则修改
        DatingGame datingGame = datingGameService.getDatingGame(datingLoginVO);
        //2.如果为空就将用户的记录，存入数据库中
        if (datingGame == null) {
            datingGameService.addDatingGame(gameTestDTO,datingLoginVO);
        }
        //3.如果不为空，则修改游戏记录
        datingGameService.updateDatingGame(gameTestDTO,datingLoginVO,datingGame.getId());
        return Result.ok();
    }

    /**
     * 结果匹配
     */
    @ApiOperation("结果匹配")
    @GetMapping("/matching")
    public Result matchingDating(@LoginDating DatingLoginVO datingLoginVO) {
       //1.去匹配所有的异性，按照游戏答案匹配.
        datingGameService.listMatchingDating(datingLoginVO);
        return Result.ok(ResultCode.DATING_SUCCESS);
    }

    /**
     * 结果返回
     */
    @ApiOperation("结果返回")
    @GetMapping("/outcome")
    public Result<List<RecommendVO>> listMatchingOutcome(@LoginDating DatingLoginVO datingLoginVO) {
        //返回匹配到的人员信息，一次五条
        List<RecommendVO> listRecommendVO = datingGameService.listMatchingOutcome(datingLoginVO);
        return Result.ok(listRecommendVO);
    }

    /**
     * 查看完整信息，支付比特币
     */
    @ApiOperation("支付比特币")
    @GetMapping("/pay/{userId}")
    public Result payBitcoin(@PathVariable Integer userId,@LoginDating DatingLoginVO datingLoginVO) {
        System.out.println("555555555"+userId);
        datingGameService.payBitcoin(userId,datingLoginVO);
        return Result.ok(ResultCode.SUCCESS);
    }
}
